﻿<%@ Page Title="" Language="C#" MasterPageFile="~/article/MasterPage.master" AutoEventWireup="true" CodeFile="topic.aspx.cs" Inherits="topic_topic" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
    <link href="../skin/jquery-ui.css" rel="Stylesheet" type="text/css" />
    <script src="../js/jquery-1.4.1.min.js" type="text/javascript"></script>
    <script type="text/javascript" src="../js/jquery-ui.min.js"></script>
    <script type="text/javascript" src="../js/xheditor-1.1.13-zh-cn.min.js"></script>
    <script type="text/javascript">
        $(document).ready(function () {
            $("#ajaxmsg").bind("ajaxSend", function () {
                $(this).html("正在加载...");
                $(this).show(100);
            }).bind("ajaxComplete", function () {
                $(this).hide(100);
            });
            inittopic();
            $("#replybtn").click(function () {
                var postdata = { "act": "addreply", "tid": getArgs().tid, "content": $("#replycontent").val() }
                $.ajax({
                    url: "../Handles/TopicHandler.ashx",
                    type: "post",
                    data: postdata,
                    dataType: "json",
                    success: function (json) {
                        if (json.success) {
                            var html = '<div id="comments"><div class="block">';
                            html += '<div class="blockBar">' + json.result + '<span style="float:right">日期：刚才</span></div>';
                            html += '<div class="blockList" style="padding-bottom:6px;">';
                            html += postdata.content;
                            html += '</div></div></div><div class="space"></div>';
                            $("#comments").append(html);
                            $("#replycontent").val("");
                        } else {
                            alert("回复失败 " + json.result);
                        }
                    }
                });
            });
        });
        function inittopic() {
            var tid = getArgs().tid;
            var postdata = { "act": "gettopic", "tid": tid }
            $.getJSON("../Handles/TopicHandler.ashx", postdata, function (data) {
                $("#title").html(data.Title);
                document.title = data.Title;
                $("#topiccontent").html(data.Content);
                $("#articleinfo").html("日期:" + ChangeDateFormat(data.EditDate));
                initreply(data.TopicID);
            });
        }
        function initreply(tid) {
            var postdata = { "act": "getreply", "tid": tid }
            $.getJSON("../Handles/TopicHandler.ashx", postdata, function (data) {
                $(data).each(function () {
                    var html = '<div id="comments"><div class="block">';
                    html += '<div class="blockBar">' + this.NickName + '<span style="float:right">日期：' + ChangeDateFormat(this.EditDate) + '</span></div>';
                    html += '<div class="blockList" style="padding-bottom:6px;">';
                    html += this.Content;
                    html += '</div></div></div><div class="space"></div>';
                    $("#comments").append(html);
                });
            });
        }
        function getArgs() {
            var args = new Object();
            var query = location.search.substring(1);      // Get query string
            var pairs = query.split("&");                  // Break at ampersand
            for (var i = 0; i < pairs.length; i++) {
                var pos = pairs[i].indexOf('=');           // Look for "name=value"
                if (pos == -1) continue;                   // If not found, skip
                var argname = pairs[i].substring(0, pos); // Extract the name
                var value = pairs[i].substring(pos + 1);     // Extract the value
                value = decodeURIComponent(value);         // Decode it, if needed
                args[argname] = value;                     // Store as a property
            }
            return args;                                   // Return the object
        }
        function ChangeDateFormat(cellval) {
            var date = new Date(parseInt(cellval.replace("/Date(", "").replace(")/", ""), 10));
            var month = date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1;
            var currentDate = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
            return date.getFullYear() + "-" + month + "-" + currentDate;
        }
    </script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ArticleTitle" Runat="Server">
<h2 id="title"></h2><div id="articleinfo" style="float:right;"></div>

</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="ArticleContent" Runat="Server">
    <div id="topiccontent"></div>
    <div class="clear"></div>
    <div class="space"></div>
    <div class="space"></div>
    <hr />
    <div class="space"></div>
    <div class="space"></div>
<div id="comments">

</div>
    <div class="space"></div>
    <div class="space"></div>
    <asp:Panel ID="replypanel" runat="server" Visible="false">
        <div class="block">
        <div class="blockBar"><asp:Label ID="username" runat="server"></asp:Label></div>
            <div class="blockList" style="padding-bottom:6px;">
                <textarea id="replycontent" class="xheditor {tools:'Cut,Copy,Paste,Pastetext,|,Source,FontColor,Preview',skin:'o2007blue',html5Upload:false}" rows="5" cols="70"></textarea>
                <div style="float:right;width:70px"><input id="replybtn" type="button" value="回复" /></div>
            </div>
      </div>
    </asp:Panel>
    <div id="ajaxmsg">AJAXMSG</div>
</asp:Content>
<asp:Content ID="Content4" ContentPlaceHolderID="rightsidebar" Runat="Server">
</asp:Content>

